"""
家具 Request VO
"""

import utils.enum_utils as enum
from models import (
    ListRequestBase,
    QueryFieldBase,
    RequestBase,
)
from models.other import (
    Dimensions,
    Vector3D,
)
from my_typing import *
from utils.data_utils.special import ObjectIdStr
from utils.validator_utils.pydantic_validator.field import (
    BodyCharField,
    BodyNormalField,
    PathCharField,
    QueryCharField,
    QueryNormalField,
)


class FamilyFurniturePathField:
    """ 家具 | 路径 | 字段 """

    furniture_id: ObjectIdStr = PathCharField(..., title="家具 ID")


class FamilyFurnitureDetailRequest(RequestBase):
    """ 家具 | 详情 | 请求 """

    furniture_id: ObjectIdStr = FamilyFurniturePathField.furniture_id


class FamilyFurnitureCreateRequest(RequestBase):
    """ 家具 | 创建 | 请求 """

    alias: StrOrNone = BodyCharField(None, title="别名", min_length=3, max_length=32)
    description: StrOrNone = BodyCharField(None, title="描述", min_length=1, max_length=200)
    dimensions: Dimensions | None = BodyNormalField(..., description="家具的尺寸（长宽高）")
    name: str = BodyCharField(..., title="名称", min_length=1, max_length=32)
    position_2_room: Vector3D | None = BodyNormalField(None, title="位置（对于房间来说）")
    room_id: ObjectIdStr = BodyCharField(..., title="房间 ID")
    type: enum.FurnitureType = BodyNormalField(..., title="家具类型")


class FamilyFurnitureUpdateRequest(FamilyFurnitureCreateRequest):
    """ 家具 | 更新 | 请求 """

    furniture_id: ObjectIdStr | None = PathCharField(..., title="家具 ID")


class FamilyFurnitureListRequest(ListRequestBase):
    """ 家具 | 列表 | 请求 """

    # -------------------- 排序字段 --------------------
    sort_by_create_time: enum.MongoSortOrNone = QueryCharField(None, title="根据创建时间排序")
    sort_by_name: enum.MongoSortOrNone = QueryCharField(None, title="根据名称排序")
    sort_by_room_id: enum.MongoSortOrNone = QueryCharField(None, title="根据房间 ID 排序")
    sort_by_type: enum.MongoSortOrNone = QueryCharField(None, title="根据家具类型排序")
    sort_by_update_time: enum.MongoSortOrNone = QueryCharField(None, title="根据更新时间排序")

    # -------------------- 查询字段 --------------------
    alias: StrOrNone = QueryCharField(None, title="根据别名模糊查询")
    description: StrOrNone = QueryCharField(None, title="根据描述模糊查询")
    name: StrOrNone = QueryCharField(None, title="根据名称模糊查询")
    room_id: ObjectIdStr | None = QueryCharField(..., title="房间 ID")
    type: enum.FurnitureType | None = QueryNormalField(..., title="家具类型")

    @classmethod
    def from_query(
        cls,
        page: int = QueryFieldBase.page,
        page_size: int = QueryFieldBase.page_size,
        sort_by_create_time: enum.MongoSortOrNone = QueryCharField(None, title="根据创建时间排序"),
        sort_by_name: enum.MongoSortOrNone = QueryCharField(None, title="根据名称排序"),
        sort_by_room_id: enum.MongoSortOrNone = QueryCharField(None, title="根据房间 ID 排序"),
        sort_by_type: enum.MongoSortOrNone = QueryCharField(None, title="根据家具类型排序"),
        sort_by_update_time: enum.MongoSortOrNone = QueryCharField(None, title="根据更新时间排序"),
        alias: StrOrNone = QueryCharField(None, title="根据别名模糊查询"),
        description: StrOrNone = QueryCharField(None, title="根据描述模糊查询"),
        name: StrOrNone = QueryCharField(None, title="根据名称模糊查询"),
        room_id: ObjectIdStr | None = QueryCharField(..., title="房间 ID"),
        type: enum.FurnitureType | None = QueryNormalField(..., title="家具类型"),  # noqa: ignore[built-in name]
    ) -> "FamilyFurnitureListRequest":
        return cls(
            page=page,
            page_size=page_size,
            sort_by_create_time=sort_by_create_time,
            sort_by_name=sort_by_name,
            sort_by_room_id=sort_by_room_id,
            sort_by_type=sort_by_type,
            sort_by_update_time=sort_by_update_time,
            alias=alias,
            description=description,
            name=name,
            room_id=room_id,
            type=type,
        )
